﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BEGDC.PreContract.BLL;

namespace PreContractWeb.Administration
{
    public partial class BGManagement : System.Web.UI.Page
    {
        private BEGDC.PreContract.BLL.Authentication.PCIdentity user;

        protected void Page_Load(object sender, EventArgs e)
        {
            user = new BEGDC.PreContract.BLL.Authentication.PCIdentity(HttpContext.Current.User.Identity);

            if (!ReportHelper.IsAdmin(user.EmployeeId))
            {
                this.divError.InnerHtml = AlertMessage.NoAdminPermission;
                this.divConnect.Visible = false;
                this.divError.Visible = true;
            }

            else
            {
                if (!this.IsPostBack)
                {
                    this.btnadd.Attributes.Add("onclick", "javascript:ShowPage(-1);");
                    this.GetData();

                }
                if (returnvalue != null && returnvalue.Value != "")
                {
                    this.GetData();
                    returnvalue.Value = "";
                }
            }
        }


        protected void GetData()
        {
            try
            {
                DataTable dt = new DataTable();
                BEGDC.PreContract.BLL.IBG bg = (BEGDC.PreContract.BLL.IBG)BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.PreContract.BLL.Services.CONST_BG_Service];
                dt = bg.GetBG_DataTable("Active = 1 OR Active = 0 ORDER BY SortNumber ASC");

                this.gvBG.DataSource = dt;
                this.gvBG.DataBind();

               
            }
            catch (Exception ex)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "\\'") + "')</script>");
            }
        }

        protected void gvBG_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                ImageButton imgedit = (ImageButton)e.Row.FindControl("imgedit");
                imgedit.Attributes.Add("onclick", "javascript:ShowPage('" + this.gvBG.DataKeys[e.Row.RowIndex].Value.ToString() + "');");

            }
        }
    }
}
